//
//  Student.m
//  Eath
//
//  Created by yuhaya on 14-9-20.
//  Copyright (c) 2014年 yuhaya. All rights reserved.
//

#import "Student.h"
#import "Tool.h"
#import "User.h"
#import "Database.h"

@implementation Student

- (id) init
{
    self = [super init];
    if (self != nil) {
        
    }
    return self;
}

- (id) initWithId:(NSString *)identify andName:(NSString *)name andAge:(NSInteger)age andSex:(NSInteger)sex andRelation:(NSString *)relation andSchool:(NSString *)school andMain:(BOOL)main andGrade:(NSString *)grade andCard:(NSString *)card andIndex:(NSInteger)index andClassName:(NSString *)class_name andEnrolTime:(NSString *)enrol_time andSchoolId:(NSString *)school_id;
{
    self = [super init];
    if (self != nil) {
        [self setId:identify andName:name andAge:age andSex:sex andRelation:relation andPhoto:nil andSchool:school andMain:main andGrade:grade andCard:card andIndex:index andClassName:class_name andEnrolTime:enrol_time andSchoolId:school_id];
    }
    return self;
}

- (void) setId:(NSString *)identify andName:(NSString *) name andAge:(NSInteger)age andSex:(NSInteger)sex andRelation:(NSString *)relation andPhoto:(NSString *)photo andSchool:(NSString *)school andMain:(BOOL)main andGrade:(NSString *)grade andCard:(NSString *)card andIndex:(NSInteger)index andClassName:(NSString *)class_name andEnrolTime:(NSString *)enrol_time andSchoolId:(NSString *)school_id
{
    self.identify = identify;
    self.name = name;
    self.age = age;
    self.sex = sex;
    self.relation = relation;
    self.photo = photo == nil ? @"default_head" : photo;
    self.school_name = school == nil ? @"默认学校" : school;
    self.grade = grade;
    self.card = card;
    self.grade = grade;
    self.main = main;
    self.class_name = class_name;
    self.enrol_time = enrol_time;
    self.index = index;
    self.school_id = school_id;
}

- (void)all_mes:(NSUInteger) timestamp
{
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:timestamp];
    NSString * day = [Tool getDateStringWithDate:date DateFormat:@"yyyy-MM-dd"];
    NSMutableArray * data = [[Database sharedDatabase] studentPointByDay:day andStuId:self.identify];
    DLog(@"%@",data);
//    DLog(@"%d",self.identify);
    [self.delegate stuPointOver:data];
}

- (void)week_point_stime:(NSString *)s_time and_etime:(NSString *)e_time
{
    DLog(@"%@===%@",s_time,e_time);
    
    NSMutableArray * date_arr = [NSMutableArray array];
    
    NSInteger stime = [[Tool getTimeampWithString:s_time DateFormat:@"yyyy-MM-dd"] integerValue];
    NSInteger etime = [[Tool getTimeampWithString:e_time DateFormat:@"yyyy-MM-dd"] integerValue];
    
    for (NSInteger a = stime; a <= etime; a+=60*60*24) {
        
        NSDate * date = [NSDate dateWithTimeIntervalSince1970:a];
        NSString * day = [Tool getDateStringWithDate:date DateFormat:@"yyyy-MM-dd"];
        [date_arr addObject:day];
    }
    
    DLog(@"%ld===%ld",stime,etime);
    
    NSMutableArray * result = [[Database sharedDatabase] weekPoint:date_arr andStuId:self.identify];
    DLog(@"%@",result);
    
    [self.delegateDuring stuPointDuringOver:result];
    
    

}
@end
